﻿<%@ Application Language="C#" %>
<%@ Import Namespace="System.Web.Routing" %>
<script RunAt="server">
   
    public static void RegisterRoutes(RouteCollection routes)
    {
        //TODO REMEMBER Am respectat o conventie pt numele routului si anume , NumeRoute = FileName
        //TODO REMEMBER in indicatiile de mai jos [ ] inseamna optional
        //TODO REMEMBER Pentru a face un link catre o pagine folositi < %$ RouteUrl:RoutName=NumeRoute [,param=val[,param=val[,...]]] %>
        //TODO REMEMBER Pentru a lua parametru din link folositi < %$RouteValue:numeParam %> !atentie par. 'id' si 'all' apare la mai multe routuri

        //TODO REMEMBER in CodeBehinde pt link foloisiti  Page.GetRouteUrl("NumeRoute",new{ [param="val"] })
        //TODO REMEMBER in CodeBehinde pt a face redirect Response.RedidectToRoute("NumeRoute")
        //TODO REMEMBER in CodeBehinde pt lua parametri   Page.RouteData.Values["numeParam"]
        
        
        //routes.MapPageRoute(
        //    "IgnoreAspxPagesRoute",                                     // Nume Route
        //    "{*tot}",                                                   // Route URL
        //    "~/Errors/404.aspx",                                        // Page that handels the route
        //    false,                                                      // check if user can acces the URL 
        //    new RouteValueDictionary { { "tot", "all.aspx" } },         // default value for "tot"
        //    new RouteValueDictionary { { "tot", @".*\.aspx(/.*)?" } }); // constraint for "tot

        routes.RouteExistingFiles = false;

        #region Store
        // /Home
        routes.MapPageRoute("", "", "~/Pages/Store/Home.aspx");
        routes.MapPageRoute("Home", "Home/{*all}", "~/Pages/Store/Home.aspx");

        routes.MapPageRoute(
            "Products",
            "Produse",
            "~/Pages/Store/Products.aspx");
        
        // /Produse/Categoria/{categoryID}/{categoryName},  WHERE categoryID =  All || [0-9]+            //+ = one or many
        routes.MapPageRoute(
            "ProductsByCategory",
            "Produse/Categoria/{categoryID}/{categoryName}",
            "~/Pages/Store/Products.aspx",
            false,
            new RouteValueDictionary { { "categoryID", "All" }, { "categoryName", "none" } },
            new RouteValueDictionary { { "categoryID", @"(([Aa])([Ll])([Ll]))|(\d+)" } });

        // /Produse/Firma/{brandID}/{brandName} ,  WHERE brandID =  All || [0-9]+            //+ = one or many
        //                          just for easy reading
        routes.MapPageRoute(
            "ProductsByBrand",
            "Produse/Firma/{brandID}/{brandName}",
            "~/Pages/Store/Products.aspx",
            false,
            new RouteValueDictionary { { "brandID", "All" }, { "brandName","none" } },
            new RouteValueDictionary { { "brandID", @"(([Aa])([Ll])([Ll]))|(\d+)" }});
        
        // /Produs/{prodID}, WHERE prodID = [0-9]+ 
        routes.MapPageRoute(
            "ProductDetails",
            "Produs/{id}/{prodName}",
            "~/Pages/Store/ProductDetails.aspx",
            false,
            new RouteValueDictionary { { "id", "0"}, { "prodName", "none" } },
            new RouteValueDictionary { { "id", @"\d+" } });

        // /WishList
        routes.MapPageRoute("WishLists", "WishLists/{*all}", "~/Pages/Store/WishLists.aspx");

        // /WishListDetails/{id}, WHERE id = [0-9]+
        routes.MapPageRoute(
            "WishListDetails",
            "WishList/{id}",
            "~/Pages/Store/WishListDetails.aspx",
            false,
            new RouteValueDictionary { { "id", "0" } },
            new RouteValueDictionary { { "id", @"\d+" } });

        // /ConstruiestePC/{prodID1/prodID2/...}, WHERE prodIDi = All | ([0-9]+)?      // ? = optional
        routes.MapPageRoute(
            "BuildPC",
            "ConstruiestePC/{id}",
            "~/Pages/Store/BuildPC.aspx",
            true,
            new RouteValueDictionary { { "id", "All" } },
            new RouteValueDictionary { { "id", @"(([Aa])([Ll])([Ll]))|(\d+)" } });
        
        // /Feedback
        routes.MapPageRoute("ContactUs", "Feedback/{*all}", "~/Pages/Store/ContactUs.aspx");

        // /Contulmeu
        routes.MapPageRoute("Profile", "ContulMeu/{*all}", "~/Pages/Store/Profile.aspx", true);

        // /Despre
        routes.MapPageRoute("About", "Despre/{*all}", "~/Pages/Store/About.aspx");
        
        // /Cautare
        routes.MapPageRoute("Cautare", "Cautare/{search}/{*all}", "~/Pages/Store/Cautare.aspx");
        #endregion
        
       
        
        #region Account
        // /Autentificare
        routes.MapPageRoute("Login", "Autentificare/{*ReturnUrl}", "~/Pages/Account/Login.aspx");

        // /Inregistrare
        routes.MapPageRoute("Register", "Inregistrare/{*RegisterParam}", "~/Pages/Account/Register.aspx");

        // /RecupereazaParola
        routes.MapPageRoute("RecoverPass", "RecupereazaParola/{*all}", "~/Pages/Account/RecoverPass.aspx");
        #endregion

        #region Admin

        routes.MapPageRoute(
            "Default",
            "Admin",
            "~/Pages/Admin/Default.aspx",
            true,
            null,
            null);
        
        // /Admin/Comanda/{id} , WHERE id =  All || [0-9]+ 
        routes.MapPageRoute(
            "Comenzi",
            "Admin/Comanda/{id}",
            "~/Pages/Admin/Comenzi.aspx",
            true,
            new RouteValueDictionary { { "id", "All" } },
            new RouteValueDictionary { { "id", @"(([Aa])([Ll])([Ll]))|(\d+)" } });
        
        // /Admin/Adauga/
        routes.MapPageRoute(
            "AdaugareProdus",
            "Admin/AdaugaProdus/{*all}",
            "~/Pages/Admin/AdaugareProdus.aspx",
            true,
            null,
            null);
        // /Admin/Atribute/ 
        routes.MapPageRoute(
            "adaugareAtribute",
            "Admin/AtributeProdus/{*all}",
            "~/Pages/Admin/adaugareAtribute.aspx",
            true,
            null,
            null);

        // /Admin/Utilizatori/ 
        routes.MapPageRoute(
            "listareUtilizatori",
            "Admin/ListaUtilizatori/{*all}",
            "~/Pages/Admin/listareUtilizatori.aspx",
            true,
            null,
            null);
        
        
        // /Admin/AdaugaFirma
        routes.MapPageRoute(
            "AdaugareBrand",
            "Admin/AdaugaFirma/{*all}",
            "~/Pages/Admin/AdaugareBrand.aspx",
            true,
            null,
            null);

        // /Admin/AfiseazaProduse
        routes.MapPageRoute(
            "AfiseazaProduse",
            "Admin/AfiseazaProduse/{*all}",
            "~/Pages/Admin/AfiseazaProduse.aspx",
            true,
            null,
            null);

        routes.MapPageRoute(
            "ModificareProdus",
            "Admin/ModificareProdus/{ID}",
            "~/Pages/Admin/ModificareProdus.aspx",
            true,
            new RouteValueDictionary { { "id", "0" } },
            new RouteValueDictionary { { "id", @"(\d)+" } });
        
        #endregion

        #region Cart
        // /Cart/{productID} WHERE productID = [0-9]+
        routes.MapPageRoute(
            "OrderInfo",
            "Comanda/{*all}",
            "~/Pages/Cart/OrderInfo.aspx",
            true,
            null,
            null);
        
        // /Cart/{all*}
        routes.MapPageRoute("MyShoppingCart", "Cart/{*all}", "~/Pages/Cart/MyShoppingCart.aspx");
        
        #endregion




    }

    private SiteMapNode SiteMap_SiteMapResolve(object sender, SiteMapResolveEventArgs e)
    {
        //TODO BUG pt pagini de exemplu (/produs/id) breadcrumb nu va fi afisat
        return null;
    }

    void Application_Start(object sender, EventArgs e)
    {
        //  Code that runs on application startup

        RegisterRoutes(RouteTable.Routes);
        SiteMap.SiteMapResolve += SiteMap_SiteMapResolve;
    }

    void Application_End(object sender, EventArgs e)
    {
        //  Code that runs on application shutdown

    }

    void Application_Error(object sender, EventArgs e)
    {
        // Code that runs when an unhandled error occurs

    }

    void Session_Start(object sender, EventArgs e)
    {
        // Code that runs when a new session is started

    }

    void Session_End(object sender, EventArgs e)
    {
        // Code that runs when a session ends. 
        // Note: The Session_End event is raised only when the sessionstate mode
        // is set to InProc in the Web.config file. If session mode is set to StateServer 
        // or SQLServer, the event is not raised.

    }
    
       
</script>
